package cn.jason.ymcc.web.controller;

import cn.jason.ymcc.dto.RegisterDto;
import cn.jason.ymcc.result.JSONResult;
import cn.jason.ymcc.service.IVerifyCodeService;
import cn.jason.ymcc.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpServerErrorException;

/**
 * 验证码接口
 *  1.图形验证码
 *  2.短信验证码
 *
 *  3.邮箱验证码
 *
 *  4.各种验证码。。。
 */
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 1.图形验证码
     *
     * @param key
     * @return
     */
    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult imageCode(@PathVariable("imageCodeKey") String key) {

        String base64Str = verifyCodeService.imageCode(key);
        return JSONResult.success(base64Str);
    }

    /**
     * 发送短信验证码
     *
     * @param mobile
     * @return
     */


    @PostMapping("/smsCode/{mobile}")
    public JSONResult smsCode(@PathVariable("mobile") String mobile) {
        verifyCodeService.smsCode(mobile);
        return JSONResult.success();
}
}